import 'sunmi_nfc_manager_platform_interface.dart';

/// NFC模块数据类
class NfcInfo {
  final String sn;
  final int type;
  final bool isSelect;
  final int waterMarkAlpha;

  NfcInfo({
    required this.sn,
    required this.type,
    required this.isSelect,
    required this.waterMarkAlpha,
  });

  factory NfcInfo.fromMap(Map<dynamic, dynamic> map) {
    return NfcInfo(
      sn: map['sn'] ?? '',
      type: map['type'] ?? 0,
      isSelect: map['isSelect'] ?? false,
      waterMarkAlpha: map['waterMarkAlpha'] ?? 0,
    );
  }

  @override
  String toString() {
    return 'NfcInfo(sn: $sn, type: $type, isSelect: $isSelect, waterMarkAlpha: $waterMarkAlpha)';
  }
}

/// 商米NFC管理器
class SunmiNfcManager {
  /// 初始化NFC管理器
  Future<bool> initialize() async {
    return await SunmiNfcManagerPlatform.instance.initialize();
  }

  /// 切换指定的NFC模块
  /// [sn] NFC模块的序列号
  Future<bool> switchNfc(String sn) async {
    return await SunmiNfcManagerPlatform.instance.switchNfc(sn);
  }

  /// 设置当前NFC模块的水印透明度
  /// [alpha] 透明度，范围0-100
  Future<bool> setNfcWaterMarkAlpha(int alpha) async {
    return await SunmiNfcManagerPlatform.instance.setNfcWaterMarkAlpha(alpha);
  }

  /// 结束注册的NFC模块监听器
  Future<bool> unregisterNfcListener() async {
    return await SunmiNfcManagerPlatform.instance.unregisterNfcListener();
  }

  /// 销毁NFC管理器
  Future<bool> destroy() async {
    return await SunmiNfcManagerPlatform.instance.destroy();
  }

  /// 获取当前NFC列表
  Future<List<NfcInfo>> getCurrentNfcList() async {
    final result = await SunmiNfcManagerPlatform.instance.getCurrentNfcList();
    return result.map((item) {
      return NfcInfo.fromMap(item);
    }).toList();
  }
}
